window.onload = function() {
    var regtel = /^1[3|4|5|7|8]\d{9}$/;  //手机号码的正则表达式
    var regqq = /^[1-9]\d{4,}$/;   // 10000 开始
    var regnickname = /^[\u4e00-\u9fa5]{2,8}$/;
    var regcode = /^\d{6}$/;   // 验证码
    var regpwd = /^[a-zA-Z0-9_-]{6,16}$/;  // 密码
    var tel = document.querySelector('#tel');
    var qq = document.querySelector('#qq');
    var nickname = document.querySelector('#nickname');
    var code = document.querySelector('#code');
    var pwd = document.querySelector('#pwd');
    var compwd = document.querySelector('#comformPwd');
    regexp(tel, regtel);  // 手机号码
    regexp(qq, regqq);  // qq
    regexp(nickname, regnickname);  // 昵称
    regexp(code, regcode);  // 短信验证码
    regexp(pwd, regpwd);  // 密码
    // 表单验证的函数
    function regexp(ele, reg) {
        ele.onblur = function() {
            if (reg.test(this.value)) {
                // console.log('正确的');
                this.nextElementSibling.className = 'success';
                this.nextElementSibling.innerHTML = '恭喜您输入正确';
            } else {
                // console.log('错误的');
                this.nextElementSibling.className = 'error';
                this.nextElementSibling.innerHTML = '格式不正确，请重新输入'
            }
        }
    };

    compwd.onblur = function() {
        if (this.value == pwd.value) {
            // console.log('正确的');
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = '恭喜您输入正确';
        } else {
            // console.log('错误的');
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = '两次密码不一致，请重新输入'
        }
    }
}